package com.battle.service.repository.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.battle.pojo.entity.Exam;
import com.battle.pojo.vo.exam.AppointQuestionJsonVo;
import com.battle.service.mapper.ExamMapper;
import com.battle.service.repository.in.ExamRepository;
import nirvana.core.repository.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import com.battle.pojo.dto.exam.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@Service
public class ExamRepositoryImpl extends Repository<ExamMapper, Exam> implements ExamRepository {

    private final ExamMapper mapper;

    public ExamRepositoryImpl(ExamMapper mapper) {
        this.mapper = mapper;
    }

    /**
     * 搜索考试管理
     *
     * @param dto
     * @return
     */
    @Override
    public Page<Exam> selectExam(SelectExamDto dto) {

        return mapper.selectExam(dto);
    }

    @Override
    public Map<Long, Exam> getMap(List<Long> ids) {
        Map<Long, Exam> map = new HashMap<>();

        if (CollectionUtil.isNotEmpty(ids)) {
            List<Exam> list = listByIds(ids);
            if (CollectionUtil.isNotEmpty(list)) {
                map = list.stream().collect(Collectors.toMap(Exam::getId, pojo -> pojo));
            }
        }
        return map;
    }

    @Override
    public Page<AppointQuestionJsonVo> getAppointQuestionList(SelectExamDto dto) {
        return mapper.getAppointQuestionList(dto);
    }
}